using System;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using System.Text;

namespace MobileClient
{
	/// <summary>
	/// Summary description for SettingValues.
	/// </summary>
	public class SettingValues
	{
		public SettingValues()
		{
		}

		public static string GetTemplatePath()
		{
			StringBuilder strPath = new StringBuilder();
			string strStorageLocation = String.Empty;
			// set path to configuration file to be the same as the application directory
			string strSettingsPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ".config";

			try
			{
				// create a new settings object to read in the configuration
				Settings objSettings = new Settings();
				objSettings.FilePath = strSettingsPath;
				objSettings.Read();
				// ge the storage location
				strStorageLocation = objSettings.StorageLocation;
				// if the storage location is device memory then set it to
				// be the same as the application
				if(strStorageLocation == "Device Memory")
				{
					strPath.Append(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName));
				}
				else
				{
					// create the path based on the storage location
					strPath.Append(strStorageLocation);
					strPath.Append("\\MobileClient");
				}
				// add the sub directoy for the forms
				strPath.Append("\\Templates");
				// create the Forms directory in case
				// it has een changed
				if(!Directory.Exists(strPath.ToString()))
				{
					Directory.CreateDirectory(strPath.ToString());
				}
			}
			catch(Exception ex)
			{
				// display the error if one occurs
				MessageBox.Show(ex.Message);
			}

			return strPath.ToString();
		}

		public static string GetResponsePath()
		{
			StringBuilder strPath = new StringBuilder();
			string strStorageLocation = String.Empty;
			// set path to configuration file to be the same as the application directory
			string strSettingsPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ".config";

			try
			{
				// create a new settings object to read in the configuration
				Settings objSettings = new Settings();
				objSettings.FilePath = strSettingsPath;
				objSettings.Read();
				// ge the storage location
				strStorageLocation = objSettings.StorageLocation;
				// if the storage location is device memory then set it to
				// be the same as the application
				if(strStorageLocation == "Device Memory")
				{
					strPath.Append(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName));
				}
				else
				{
					// create the path based on the storage location
					strPath.Append(strStorageLocation);
					strPath.Append("\\MobileClient");
				}
				// add the sub directoy for the forms
				strPath.Append("\\Responses");
				// create the Forms directory in case
				// it has een changed
				if(!Directory.Exists(strPath.ToString()))
				{
					Directory.CreateDirectory(strPath.ToString());
				}
			}
			catch(Exception ex)
			{
				// display the error if one occurs
				MessageBox.Show(ex.Message);
			}

			return strPath.ToString();
		}

		public static string GetImagePath()
		{
			StringBuilder strPath = new StringBuilder();
			string strStorageLocation = String.Empty;
			// set path to configuration file to be the same as the application directory
			string strSettingsPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ".config";

			try
			{
				// create a new settings object to read in the configuration
				Settings objSettings = new Settings();
				objSettings.FilePath = strSettingsPath;
				objSettings.Read();
				// ge the storage location
				strStorageLocation = objSettings.StorageLocation;
				// if the storage location is device memory then set it to
				// be the same as the application
				if(strStorageLocation == "Device Memory")
				{
					strPath.Append(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName));
				}
				else
				{
					// create the path based on the storage location
					strPath.Append(strStorageLocation);
					strPath.Append("\\MobileClient");
				}
				// add the sub directoy for the forms
				strPath.Append("\\Images");
				// create the Forms directory in case
				// it has een changed
				if(!Directory.Exists(strPath.ToString()))
				{
					Directory.CreateDirectory(strPath.ToString());
				}
			}
			catch(Exception ex)
			{
				// display the error if one occurs
				MessageBox.Show(ex.Message);
			}

			return strPath.ToString();
		}

		public static string GetUserId()
		{
			string strUserId = String.Empty;
			// set path to configuration file to be the same as the application directory
			string strSettingsPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ".config";

			try
			{
				// create a new settings object to read in the configuration
				Settings objSettings = new Settings();
				objSettings.FilePath = strSettingsPath;
				objSettings.Read();
				// ge the storage location
				strUserId = objSettings.UserID;
			}
			catch(Exception ex)
			{
				// display the error if one occurs
				MessageBox.Show(ex.Message);
			}

			return strUserId;
		}
	}
}
